<template>
  <div id="app">
    <h2>测试题</h2>
    <subject-item :arr="arr" @submit="handleSum"></subject-item>
    <div>
      <flag-item :arr="arr"></flag-item>
    </div>
  </div>
</template>

<script>
import FlagItem from './components/FlagItem.vue';
import SubjectItem from './components/SubjectItem.vue';

export default {
  components: { SubjectItem, FlagItem },
  data(){
    return {
      arr:[
        {
          num1:Math.floor(Math.random()*10),
          num2:Math.floor(Math.random()*10),
          result:'',
          status:'未完成'
        },
        {
          num1:Math.floor(Math.random()*10),
          num2:Math.floor(Math.random()*10),
          result:'',
          status:'未完成'
        },
        {
          num1:Math.floor(Math.random()*10),
          num2:Math.floor(Math.random()*10),
          result:'',
          status:'未完成'
        },
        {
          num1:Math.floor(Math.random()*10),
          num2:Math.floor(Math.random()*10),
          result:'',
          status:'未完成'
        },
        {
          num1:Math.floor(Math.random()*10),
          num2:Math.floor(Math.random()*10),
          result:'',
          status:'未完成'
        }
      ]
    }
  },
  methods:{
    handleSum(i,val){
      const result =  this.arr[i].num1+this.arr[i].num2
      console.log(result)
      if(!val){
        this.arr[i].status='未完成'
      } else if (result === val){
        this.arr[i].status = '回答正确'
      } else {
        this.arr[i].status = '回答错误'
      }
      console.log(this.arr[i].status)
    }
  }
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>